<?php

require_once 'init.php';

$tname = 'raspred_attributes';

$groupId = 'raspred';

$group = cf\api\shop\getCategory($groupId);
$smarty->assign('group',$group);

$attrs = cf\param::exist('a') ? cf\param::get('a') : array();

$sql = '';
$params = array();
foreach ($attrs as $id => $val) {
	if ($val) {
		$params[$id] = $val;
		$sql[] = "$id=:$id";
	}
}

$qFindProduct = cf\createQuery("SELECT * FROM cf_products WHERE id=:id OR code=:id");
$all = cf\query2arrays("SELECT * FROM raspred_attributes".(empty($params)?'':" WHERE ".implode(' AND ',$sql)), $params);
foreach ($all as &$item) {
	$id = array();
	if (preg_match('/\d+\s*$/',$item['model'],$id)) {
		$product = cf\query2array($qFindProduct, array('id'=>$id[0]));
		$item['product_id'] = trim($product['id']);
		$item['product_name'] = $product['name'].' '.$product['model'];
	}
}

$smarty->assign('found',$all);

show(
	'search', 
	'Поиск по атрибутам', 
	array_merge($group['branch'],array(array('name'=>'Поиск')))
);


?>